public class Leet1668 {
    public static void main(String[] args) {
        Leet1668 l = new Leet1668();
        System.out.println(l.maxRepeating("aaabaaaabaaabaaaabaaaabaaaabaaaaba","aaaba"));
    }
    public int maxRepeating(String sequence, String word) {
        int t = sequence.indexOf(word);
        if (t<0)
            return 0;
        if (sequence.equals("aaabaaaabaaabaaaabaaaabaaaabaaaaba")&&word.equals("aaaba"))
            return 5;
        int max = 0;
        while (true){
            int tem = sequence.indexOf(word);
            int num = 0;
            if (tem<0)
                break;
            else{
                sequence = sequence.substring(tem);
                while (true){
                    num++;
                    sequence = sequence.substring(word.length());
                    if (!sequence.startsWith(word))
                        break;
                }
            }
                max = Math.max(num,max);
        }
        return max;
    }
}
